package cn.dakaqi.utils.file;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;

public class FileHelp {

	static Logger log = LoggerFactory.getLogger(FileHelp.class);
	/*
	 * 文件名重命名
	 * @path 文件所属目录
	 * @name 原文件名
	 * @newName 新文件名
	 */
	public static void ReName(String path,String name,String newName){
		//删除已存在的文件
		try {
			if(!name.equals(newName)){
				File file = new File(path+name);
				String os = checkOS();
				
				if (os != null && os.startsWith("Windows")) {
					file.renameTo(new File(path+newName));
					//FileUploadUtil.copyFile(file, new File(path+newName));
				}
				else
				{
					String command = "mv " + path + name +" " + path +newName;
					Runtime.getRuntime().exec(command);
				}
				
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();log.error(e.getMessage());

		}
	}
	
	/**
	 * 判断操作系统类型
	 * @return
	 */
	public static String checkOS()
	{
		String os = System.getProperty("os.name");         
		return os;
	}
}
